package sample;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import service.Jedis;
@Controller
@RequestMapping(value="/string")
public class stringSample {
	@Resource(name="jedis-client")
	Jedis jedis;
	@RequestMapping(value="/exists/{key}")
	public String isExists(@PathVariable("key")String key,Model model){
		model.addAttribute("code","boolean exists(String key);");
		model.addAttribute("result",jedis.exists(key));
		return "result";
	}
	@RequestMapping(value="/get/{key}")
	public String get(@PathVariable("key")String key,Model model){
		model.addAttribute("code","String get(String key);");
		model.addAttribute("result",jedis.get(key));
		return "result";
	}
	
	@RequestMapping(value="/set/{key}/{value}")
	public String set(@PathVariable("key")String key,@PathVariable("value")String value,Model model){
		model.addAttribute("code","String set(String key, String value);");
		model.addAttribute("result",jedis.set(key, value));
		return "result";
	}
	
	@RequestMapping(value="/del/{keys}")
	public String del(@PathVariable("key")String keys,Model model){
		model.addAttribute("code","long del(String... keys);");
		String [] key=keys.split(":");
		model.addAttribute("result",jedis.del(key));
		return "result";
	}
	
	
}
